package com.sc.VenusQueryBeta.presenter.account.xiadaikuan;

import com.hengjun.kingstar.sdk.utils.LogUtils;
import com.sc.VenusQueryBeta.contract.account.xiadaikuan.XiaDaiKuan01Contract;
import com.sc.VenusQueryBeta.model.account.xiadaikuan.XiaDaiKuan01Model;
import com.sc.VenusQueryBeta.model.bean.account.AllRoomListBean;
import com.sc.VenusQueryBeta.model.bean.account.CurrencyListBean;
import com.sc.VenusQueryBeta.model.bean.account.xiadaikuan.XiaDaiKuan01Bean;

import io.reactivex.functions.Consumer;

/**
 * Created by Administrator on 2018/10/21.
 *
 */

public class XiaDaiKuan01Presenter extends XiaDaiKuan01Contract.XiaDaiKuan01Presenter {

    @Override
    protected XiaDaiKuan01Contract.IXiaDaiKuan01Model getModel() {
        return XiaDaiKuan01Model.newInstance();
    }

    @Override
    public void onStart() {

    }

    public static XiaDaiKuan01Presenter newInstance(){
        return new XiaDaiKuan01Presenter();
    }
    /**
     *  获取下线贷款01
     * @param serverAddress
     * @param projectName
     * @param serverPort
     * @param clientindex
     * @param currencynameCN
     */
    @Override
    public void getXiaDaiKuan01(String serverAddress, String projectName, int serverPort, int clientindex, String currencynameCN) {
        if (mIView == null || mIModel == null)
            return;
        mRxManager.register(mIModel.getXiaDaiKuan01(serverAddress,projectName, serverPort,clientindex,currencynameCN).subscribe(new Consumer<XiaDaiKuan01Bean>() {
            @Override
            public void accept(XiaDaiKuan01Bean xiaDaiKuan01Bean) throws Exception {
                if (mIView != null)
                mIView.showXiaDaikuanData1Success(xiaDaiKuan01Bean);

            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
                if (mIView != null) {
//                    if (mIView.isVisiable())
                    LogUtils.e("第一次加載 error=="+throwable.getMessage());
                    mIView.showToast("Network error");
                    mIView.showNetworkError(throwable);
                }
            }
        }));
    }

    @Override
    public void queryAllCurrencyList(String serverAddress, String projectName, int serverPort) {
        if (mIView == null || mIModel == null)
            return;
        mRxManager.register(mIModel.queryAllCurrencyList(serverAddress,projectName,serverPort).subscribe(new Consumer<CurrencyListBean>() {
            @Override
            public void accept(CurrencyListBean currencyListBean) throws Exception {
                mIView.showqueryAllCurrencyList(currencyListBean);
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
                LogUtils.e("Network error."+throwable.getMessage());
//                if (mIView != null)
//                    return;
                mIView.showToast("Network error.");
                mIView.showNetworkError(throwable);
            }
        }));
    }

//    /**
//     * 查询厅
//     * @param serverAddress
//     * @param projectName
//     * @param serverPort
//     */
//    @Override
//    public void queryAllRoomList(String serverAddress, String projectName, int serverPort) {
//        if (mIView == null || mIModel == null)
//            return;
//        mRxManager.register(mIModel.queryAllRoomList(serverAddress,projectName,serverPort).subscribe(new Consumer<AllRoomListBean>() {
//            @Override
//            public void accept(AllRoomListBean allRoomListBean) throws Exception {
//                mIView.showqueryAllRoomList(allRoomListBean);
//            }
//        }, new Consumer<Throwable>() {
//            @Override
//            public void accept(Throwable throwable) throws Exception {
//                LogUtils.e("Network error."+throwable.getMessage());
////                if (mIView != null)
////                    return;
//                mIView.showToast("Network error.");
//                mIView.showNetworkError(throwable);
//            }
//        }));
//    }

}



